package com.library.verification.view;

import android.content.Context;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.library.verification.R;

/**
 * Created by zhoulikai on 17/4/21.
 * 验证码组件基类
 */

public abstract class BaseVerificationView extends LinearLayout implements IVerificationView {
    public BaseVerificationView(Context context) {
        super(context);
        init(context, null);
    }

    public BaseVerificationView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public BaseVerificationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public BaseVerificationView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        LayoutInflater.from(context).inflate(setVerificationViewId(), this);
        initView(context, attrs);
    }

    protected abstract int setVerificationViewId();

    protected abstract void initView(Context context, AttributeSet attrs);

    @Override
    public View generateView() {
        return this;
    }

    @Override
    public void dismiss() {

    }
}
